<?php

include 'lib/ActionsConnection.php';
include 'lib/ExamModifier.php';

// If the key is send via POST, use POST instead of GET.
if(isset($_POST['k'])){
    $_GET = $_POST;
}

$user = $_GET['u'];
$pass = $_GET['p'];
$exam = $_GET['e'];
$action = $_GET['a'];
$key = $_GET['k'];

// $action can either be "signup" or "signoff"
if(!isValidApp($key)){
    $status = "INVALID_KEY";
} else if($user == null || $pass == null || $exam == null || $action == null){
    $status = "INCOMPLETE_DATA";
} else {
    $actions = new ActionsConnection($user, $pass, $key);
    $status = $actions->status;
    
    if($status == "OK"){
        $modifier = new ExamModifier($actions, $exam);
        if($action == "signup"){
            $modifier->signup();
        } else if ($action == "signoff") {
            $modifier->signoff();
        } else {
            $status = "ERROR";
        }
    }
}

$actions->destroy();

header ("Content-Type:text/xml");

echo '<Status>'.$status.'</Status>';

?>